package cn.hua.trip.base.service.impl;

import cn.hua.trip.base.domain.TravelCommend;
import cn.hua.trip.base.mapper.TravelCommendMapper;
import cn.hua.trip.base.query.TravelCommendQueryObject;
import cn.hua.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService{
    @Autowired
    private TravelCommendMapper travelCommendMapper;

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if (travelCommend.getId()==null) {
            travelCommendMapper.insert(travelCommend);
        }else{
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    @Override
    public PageInfo<TravelCommend> query(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.queryForList(qo);
        return new PageInfo<TravelCommend>(list);
    }

    @Override
    public List<Map> selectTravelCommendByState(TravelCommendQueryObject qo) {
         return travelCommendMapper.selectTravelCommendByState(qo);
    }

    @Override
    public PageInfo<TravelCommend> selectTravelCommendByType(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        PageInfo<TravelCommend> list = travelCommendMapper.selectTravelCommendByType(qo);
        return new PageInfo<TravelCommend>();
    }

    @Override
    public PageInfo<Map> queryForListApp(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Map> list = travelCommendMapper.queryForListApp(qo);
        return new PageInfo<>(list);
    }
}
